package com.sydsen.imager.util;

import sun.font.FontDesignMetrics;

import java.awt.*;

/**
 * @Auther: syh
 * @Date: 2021/11/8
 * @Description:
 */
public class FontUtil {


    public static int getTextWidth(String text, Font font) {
        FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font);
        int width = 0;
        for (int i = 0; i < text.length(); i++) {
            width += metrics.charWidth(text.charAt(i));
        }
        return width;
    }
}
